import glob
import cv2
import numpy as np
#
def salt(img, n):
    # 循环添加n个椒盐
    for k in range(n):
        # 随机选择椒盐的坐标
        i = int(np.random.random() * img.shape[1])
        j = int(np.random.random() * img.shape[0])
        # 如果是灰度图
        if img.ndim == 2:
            img[j,i] = 255
        # 如果是RBG图片
        elif img.ndim == 3:
            img[j,i,0]= 255
            img[j,i,1]= 255
            img[j,i,2]= 255
    return img

i = 54
for img_name in glob.glob("test/cache/*.jpg"):
    img = cv2.imread(img_name)
    img = cv2.resize(img,(256,256))
    # dst1 = cv2.GaussianBlur(img, (5, 5), 0)
    # dst2 = cv2.flip(img,1)
    # dst3 = salt(img,1000)

    i+=1
    cv2.imwrite('./test/cache/1_'+str(i)+'.jpg',img)
    # i+=1
    # cv2.imwrite('./test/cache/1_' + str(i) + '.jpg', dst1)
    # i+=1
    # cv2.imwrite('./test/cache/1_' + str(i) + '.jpg', dst2)
    # i+=1
    # cv2.imwrite('./test/cache/1_' + str(i) + '.jpg', dst3)


# i=-1
# for img_name in glob.glob("dataset/laptop/*.jpg"):
#     img = cv2.imread(img_name)
#     img = cv2.resize(img,(256,256))
#     dst1 = cv2.GaussianBlur(img, (5, 5), 0)
#     dst2 = cv2.flip(img,1)
#     dst3 = salt(img,1000)
#
#     i+=1
#     cv2.imwrite('./dataset/laptop/1_'+str(i)+'.jpg',img)
#     i+=1
#     cv2.imwrite('./dataset/laptop/1_' + str(i) + '.jpg', dst1)
#     i+=1
#     cv2.imwrite('./dataset/laptop/1_' + str(i) + '.jpg', dst2)
#     i+=1
#     cv2.imwrite('./dataset/laptop/1_' + str(i) + '.jpg', dst3)
#

######################
# i = -1
# for img_name in glob.glob("dataset/chip/*.jpg"):
#     img = cv2.imread(img_name)
#     img = cv2.resize(img,(256,256))
#     i+=1
#     cv2.imwrite('./dataset/chip/0_'+str(i)+'.jpg',img)
# i=-1
# for img_name in glob.glob("dataset/laptop/*.jpg"):
#     img = cv2.imread(img_name)
#     img = cv2.resize(img,(256,256))
#
#
#     i+=1
#     cv2.imwrite('./dataset/laptop/1_'+str(i)+'.jpg',img)